﻿@model ForumPageModel
@using IT.CMS.Core.Domain.Forums;
@using IT.CMS.Web.Extensions;
@using IT.CMS.Web.Models.Boards;
@using IT.CMS.Web.Models.Common;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    Html.AddTitleParts(Model.Name);
}
<script type="text/javascript">
    function handleForumWatch(context) {
        $('#watch-forum').text(context.Text);
    }
</script>
<div class="page forum">
    @Html.Action("ForumBreadcrumb", new { forumId = Model.Id })    
    <div class="clear">
    </div>
    <div class="top">
        <div class="forum-info">
            <div class="forum-name">
                @Model.Name</div>
            <div class="forum-description">
                @Model.Description</div>
            @if (Model.ForumFeedsEnabled)
            {
                <div class="rss">
                    <a href="@Url.RouteUrl("ForumRSS", new { id = Model.Id })" class="link-rss" title="@T("Forum.ForumRSSLinkTitle")">@T("Forum.RSS")</a>
                </div>
            }
        </div>
        <div class="actions">
            <div>
                @Html.RouteLink(T("Forum.NewTopic").ToString(), "TopicCreate", new { id = Model.Id }, new { @class = "newtopic" })
                @if (Model.IsCustomerAllowedToSubscribe)
                {
                    @Ajax.RouteLink(Model.WatchForumText,
                                "ForumWatch",
                                new { id = Model.Id },
                                new AjaxOptions { HttpMethod = "Post", OnSuccess = "handleForumWatch" },
                                new { id = "watch-forum", @class = "watch-forum" })
                }
            </div>
            @Html.Partial("_SearchBox")
        </div>
    </div>
    <div class="clear">
    </div>
    <div class="pager">
        @{
            var pager = Html.Pager(new PagerModel()
            {
                PageSize = Model.TopicPageSize,
                TotalRecords = Model.TopicTotalRecords,
                PageIndex = Model.TopicPageIndex,
                ShowTotalSummary = false,
                RouteActionName = "ForumSlugPaged",
                UseRouteLinks = true,
                RouteValues = new RouteValues { id = Model.Id, slug = Model.SeName }
            });
        }
        @pager
    </div>
    <div class="clear">
    </div>
    <div class="topics-group">
        <table class="topics">
            @if (Model.ForumTopics.Count > 0)
            {
                <tr class="forum-header">
                    <td class="topic-name" colspan="2">
                        @T("Forum.TopicTitle")
                    </td>
                    <td class="replies">
                        @T("Forum.Replies")
                    </td>
                    <td class="views">
                        @T("Forum.Views")
                    </td>
                    <td class="last-post">
                        @T("Forum.LatestPost")
                    </td>
                </tr>
            }
            @foreach (var topic in @Model.ForumTopics)
            {
                <tr class="topic">
                    <td>
                        @{
                var topicType = "post";
                var topicText = String.Empty;
                switch (topic.ForumTopicType)
                {
                    case ForumTopicType.Normal:
                        topicType = "post";
                        break;
                    case ForumTopicType.Sticky:
                        topicType = "poststicky";
                        topicText = string.Format("[{0}]", T("Forum.Sticky").ToString());
                        break;
                    case ForumTopicType.Announcement:
                        topicType = "post-annoucement";
                        topicText = string.Format("[{0}]", T("Forum.Announcement").ToString());
                        break;
                    default:
                        topicType = "post";
                        break;
                }
                            <div class="@topicType">
                            </div>
                        }
                    </td>
                    <td class="topic-name">
                        @if (!String.IsNullOrEmpty(topicText))
                        {
                            <span class="topictype">@topicText</span>
                        }
                        @Html.RouteLink(topic.Subject, "TopicSlug", new { id = topic.Id, slug = topic.SeName }, new { @class = "topic-title" })
                        @if (topic.NumPosts > Model.PostsPageSize)
                        {   
                            <div class="topicspager">
                                @Html.ForumTopicSmallPager(topic)
                            </div>
                        }
                        <div class="topic-starter">
                            @if (topic.CustomerId > 0)
                            {
                                if (topic.AllowViewingProfiles && !topic.IsCustomerGuest)
                                {
                                @T("Forum.Author")<text>:</text> @Html.RouteLink(topic.CustomerName, "CustomerProfile", new { Id = topic.CustomerId })
                                }
                                else
                                {
                                @T("Forum.Author")<text>:</text> @topic.CustomerName
                                }
                            }
                        </div>
                    </td>
                    <td class="replies">
                        @topic.NumReplies
                    </td>
                    <td class="views">
                        @topic.Views
                    </td>
                    <td class="last-post">
                        @Html.Action("LastPost", new { forumPostId = topic.LastPostId, showTopic = false })
                    </td>
                </tr>
            }
        </table>
    </div>
    <div class="clear">
    </div>
    <div class="pager">
        @pager
    </div>
</div>
